local exit_frame = 6

AddStategraphState('wilson',State{
    name = "webbert_quickchop",
    tags = {'busy','doing','tilling'},
    onenter = function(inst)
        inst.components.locomotor:Stop()

        -- local equippedTool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
		-- 	if equippedTool ~= nil and equippedTool.components.tool ~= nil and equippedTool.components.tool:CanDoAction(ACTIONS.DIG) then
        --     --upside down tool build
        --     inst.sg.statemem.fliptool = true
        -- end

        inst.AnimState:PlayAnimation("woodie_chop_loop", false)
        inst.sg:SetTimeout(exit_frame*FRAMES)
    end,
    timeline = {
        TimeEvent(4*FRAMES, function(inst)
            -- inst.SoundEmitter:PlaySound("dontstarve/common/together/houndwhistle")
            inst:PerformBufferedAction()
        end),
        TimeEvent(exit_frame*FRAMES, function(inst)
            -- inst.SoundEmitter:PlaySound("dontstarve/common/together/houndwhistle")
            inst.sg:RemoveStateTag("busy")
        end),
    },
    ontimeout = function(inst)
        inst.sg:GoToState("idle", true)
    end,
    events =
    {
        EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end),
        EventHandler("animover", function(inst)
            inst.sg:GoToState("idle", true)
        end),
    },
})

AddStategraphState('wilson_client',State{
    name = 'webbert_quickchop',
    tags = {'busy','doing'},
    onenter = function(inst)
        inst.components.locomotor:Stop()
        -- local equippedTool = inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
        -- if equippedTool ~= nil and equippedTool:HasTag("DIG_tool") then
        --     inst.sg.statemem.fliptool = true
        -- end

        inst.AnimState:PlayAnimation("woodie_chop_loop", false)
        -- inst.sg:SetTimeout(inst.AnimState:GetCurrentAnimationLength())
        inst:PerformPreviewBufferedAction()
        inst.sg:SetTimeout((exit_frame+4)*FRAMES)

    end,
    ontimeout = function(inst)
        inst:ClearBufferedAction()
        inst.sg:GoToState("idle", true)
    end,
    -- events=
    -- {
    --     EventHandler("animover", function(inst)
    --         inst.sg:GoToState("idle")
    --     end),
    -- },
})
